package com.oolee.cloud.controller;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.oolee.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "globalFallback")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @GetMapping(value = "/payment/health/{id}")
    public String Health(@PathVariable("id")long id){
        return paymentService.requestHealth(id);
    }

    @GetMapping(value = "/payment/unHealth/{id}")
    public String UnHealth(@PathVariable("id")long id){
        return paymentService.requestUnHealth(id);
    }

    @GetMapping(value = "/payment/exception")
    @HystrixCommand
    public String requestException(){
        int num = 10/0;
        return "不可能返回这段话。。。";
    }

    public String globalFallback(){
        return "全局默认fallback提示您: --> 太慢了 o(╥﹏╥)o";
    }

    @GetMapping(value = "/{id}")
    public String CircuitBreaker(@PathVariable("id")long id){
        return this.paymentService.paymentCircuitBreaker(id);

    }
}
